package com.example.demo3_drug.common;


import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.HashMap;

/*
* 给前端返回的json格式
* */
public class ResultMapUtil {
    /*
    * 登录返回结果
    * */
    public static HashMap<String,Object> getHashMapLogin(String msg,String code){
        HashMap<String,Object> resultMap = new HashMap<>();
        resultMap.put("msg",msg);
        resultMap.put("code",code);

        // 1 返回正确的结果
        if ("1".equals(code)){
            resultMap.put("icon",1);
            resultMap.put("anim",4);
        }else{
            resultMap.put("anim",3);
        }

        resultMap.put("anim",4);

        return resultMap;
    }


    /**
     * 分页查询数据
     * */
    public static HashMap<String,Object> getHashMapMysqlPage(IPage<?> object){
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("code",0);
        resultMap.put("msg","");
        resultMap.put("count",object.getTotal());
        resultMap.put("data",object.getRecords());

        return resultMap;
    }

    /**
     * 异常数据统一处理
     * */

    public static HashMap<String,Object> getHashMapException(Exception e){
        HashMap<String, Object> resultMap = new HashMap<>();
        resultMap.put("code",0);
        resultMap.put("msg",e.getMessage());

        return resultMap;
    }

    /**
     *
     * @param i
     * @return
     */
    public static HashMap<String,Object> getHashMapSave(int i){
        HashMap<String, Object> resultMap = new HashMap<>();
        if (i==0){

            resultMap.put("msg","保存失败");
            resultMap.put("code",1);
            resultMap.put("icon",5);
            resultMap.put("anim",6);

        }else {
            resultMap.put("msg","保存成功");
            resultMap.put("code",0);
            resultMap.put("icon",1);
            resultMap.put("anim",4);
        }

        return resultMap;
    }

    /**
     *
     * @param i
     * @return
     */
    public static HashMap<String,Object> getHashMapDel(int i){
        HashMap<String, Object> resultMap = new HashMap<>();
        if (i==0){

            resultMap.put("msg","删除失败");
            resultMap.put("code",1);
            resultMap.put("icon",5);
            resultMap.put("anim",6);

        }else {
            resultMap.put("msg","删除成功");
            resultMap.put("code",0);
            resultMap.put("icon",1);
            resultMap.put("anim",4);
        }

        return resultMap;
    }

}
